home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-24 | 4.5 KB | 127 lines | [TEXT/CCL2] |
- (in-package :oou)
- (provide :graphic-rsrc-svm)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; graphic-rsrc-svm.lisp
- ;;
- ;; Copyright © 1991 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; mixin for displaying graphical resources in views
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (oou-dependencies
- :rsrc-svm
- :simple-view-ce)
-
-
- (export '(graphic-rsrc-svm))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- #|
-
- graphic-rsrc-svm adds resource based graphics to views.
-
- See Also
- rsrc-svm - inherited behavior
-
-
- Initargs
-
- :graphic-scaling [:adjust-view-size]
- Determines if the graphic is scaled to the view size or vice-versa.
- Allowed keywords are :adjust-view-size, :scale-to-view, :clip-to-view.
- :adjust-view-size - the view size is adjusted to fit the graphic
- :scale-to-view - the graphic is scaled to the view size.
- :clip-to-view - the graphic is drawn clipped to the view
-
-
- Methods of Interest
-
- graphic-size (sv graphic-rsrc-svm) rsrc-handle
- Returns the size of the specified graphic as a point.
- e.g. PICT-svm's return:
- (subtract-points
- (href rsrc-handle :Picture.picFrame.botRight)
- (href rsrc-handle :Picture.picFrame.topLeft ))
-
- draw-graphic (sv graphic-rsrc-svm) rsrc-handle rect
- Draws the graphic scaled to rect.
-
- graphic-margins (sv graphic-rsrc-svm)
- Returns margins for indenting the graphic as two points (topLeft, botRight).
- The default method returns zero margins. Specialize this method to control
- placement.
-
- |#
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defclass graphic-rsrc-svm (rsrc-svm)
- ((graphic-scaling :initarg :graphic-scaling)
- (graphic-default-size :initarg :graphic-default-size))
- (:default-initargs
- :graphic-scaling :adjust-view-size
- :graphic-default-size #@(32 32)
- ))
-
- (defmethod graphic-size ((sv graphic-rsrc-svm) rsrc-handle)
- (declare (ignore rsrc-handle))
- (slot-value sv 'graphic-default-size))
-
- (defmethod draw-graphic ((sv graphic-rsrc-svm) rsrc-handle rect)
- (declare (ignore sv rsrc-handle rect)))
-
- (defmethod view-draw-contents ((sv graphic-rsrc-svm))
- (with-slots (rsrc-handle) sv
- (multiple-value-bind (topLeft botRight) (graphic-corners sv)
- (ecase (slot-value sv 'graphic-scaling)
- (:scale-to-view (rlet ((r :Rect :topLeft topLeft :botRight botRight))
- (draw-graphic sv rsrc-handle r)))
- (:adjust-view-size (rlet ((r :Rect
- :topLeft topLeft
- :botRight (add-points topLeft (graphic-size sv rsrc-handle))))
- (draw-graphic sv rsrc-handle r)))
- (:clip-to-view (rlet ((clip-rect :Rect
- :topLeft topLeft
- :botRight botRight)
- (r :Rect :topLeft topLeft :botRight (add-points topLeft (graphic-size sv rsrc-handle))))
- (with-clip-rect clip-rect
- (draw-graphic sv rsrc-handle r)))))))
- (call-next-method))
-
- (defmethod graphic-margins ((sv graphic-rsrc-svm))
- (declare (ignore sv))
- (values #@(0 0) #@(0 0)))
-
- (defmethod graphic-corners ((sv graphic-rsrc-svm))
- (multiple-value-bind (topLeft botRight) (focused-corners sv)
- (multiple-value-bind (tl-margin br-margin) (graphic-margins sv)
- (values (add-points topLeft tl-margin) (subtract-points botRight br-margin)))))
-
- (defmethod view-default-size ((sv graphic-rsrc-svm))
- (add-points (multiple-value-call #'add-points (graphic-margins sv))
- (slot-value sv 'graphic-default-size)))
-
- (defmethod scale-view-size ((sv graphic-rsrc-svm))
- (when (slot-boundp sv 'rsrc-handle)
- (with-slots (rsrc-handle) sv
- (let ((margin-size (multiple-value-call #'add-points (graphic-margins sv))))
- (set-view-size sv (add-points (graphic-size sv rsrc-handle) margin-size))))))
-
- (defmethod set-view-size :before ((sv graphic-rsrc-svm) h &optional v)
- (declare (ignore h v))
- (erase-view sv))
-
- (defmethod rsrc-handle-install :after ((sv graphic-rsrc-svm))
- (if (eq :adjust-view-size (slot-value sv 'graphic-scaling))
- (scale-view-size sv)
- (invalidate-view sv t)))
-
- (defmethod set-view-resource :after ((sv graphic-rsrc-svm) &key rsrc-type rsrc-id rsrc-name rsrc-handle)
- (declare (ignore rsrc-type rsrc-id rsrc-name rsrc-handle))
- (invalidate-view sv t))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-